package com.sky.kafkaDemo.service.impl;

import com.sky.kafkaDemo.entity.User;
import com.sky.kafkaDemo.entity.common.constant.MqConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

@Service
public class KafkaProducerServiceImpl {


    @Autowired
    private KafkaTemplate<String, Object> kafkaTemplate;

    /**
     * 发送string类型消息
     */
    public void sendMessage(String message) {
        kafkaTemplate.send(MqConstant.TOPIC_STRING, message);
    }

    /**
     * 发送Object类型消息
     */
    public void sendUser(User user) {
        kafkaTemplate.send(MqConstant.TOPIC_USER, user);
    }

}